﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace DuoMi.MallCustomerService.Web.Controls.List
{
    /// <summary>
    /// RemoteListHandler 的摘要说明
    /// </summary>
    public class RemoteListHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string strResult = string.Empty;
            if (context.Request["action"] == null)
            {
                context.Response.Write("ERROR|无法找到action属性");
                return;
            }
            try
            {
                switch (context.Request["action"].ToUpper())
                {
                    case "GETREMOTEURLTEXT":
                        strResult = this.GetRemoteUrlText(context);
                        break;
                }
            }
            catch (Exception ex)
            {
                strResult = "ERROR|出现异常：" + ex.Message;
            }
            //统一输出响应信息
            context.Response.Write(strResult);
        }

        private string GetRemoteUrlText(HttpContext context)
        {
            string result = string.Empty;
            string remoteUrl = context.Request["remoteUrl"];
            string encoding = context.Request["encoding"];
            if (!DuoMi.Framework.Common.Net.HttpRequester.Get(remoteUrl,Encoding.GetEncoding(encoding), ref result))
                result = "ERROR|" + result;
            return result;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}